<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">

		<%include("/common/include.html"){}%>
	</head>

	<body class="easyui-layout">
			<table id="dailySaleTotal_datagrid" class="easyui-datagrid" style="height:100%;">
		
			</table>
			<div id="sale_tb" >
			
				<label class="label-top" style="width: 100%; display: block;">日期</label>
				<input  id="dailyTotal_datebox" name="month"  class="easyui-datebox theme-textbox-radius"style="height: 32px; width: 212px; text-align: center" />
			
				<input name="organIds" id="organIds" type="hidden" value="${organization.ids! }">
			</div>
			
		
		<script type="text/javascript">
			$(document).ready(function () {
				dateFormatter();
				//加载数据表格
				loadTable();
				$('#dailyTotal_datebox').datebox({
					onChange: function(date){
						loadTable();
					}
				});
			});
			
			function  loadTable()
			{	
				var columnsAll = new Array();
				columnsAll.push({field:'ids',title:'ids',align:'center',rowspan:2,hidden:true});
				columnsAll.push({field:'date',title:'日期',align:'center',rowspan:2});
				columnsAll.push({field:'pricetotal',title:'合计',width:60,rowspan:2,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'dyxslj',title:'累计',width:65,rowspan:2,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'cjrs',title:'新增',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					},rowspan:2});
				columnsAll.push({field:'zjscjrs',title:'转介绍',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					},rowspan:2});
				columnsAll.push({field:'zrjdcjrs',title:'自然<br/>进店',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					},rowspan:2});
				
				columnsAll.push({field:'lc002',title:'单疗程',colspan:2,align:'center'});
				columnsAll.push({field:'lc001',title:'标准疗程',colspan:2,align:'center'});
				columnsAll.push({field:'zr',title:'转入',rowspan:2,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'zc',title:'转出',rowspan:2,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				
				columnsAll.push({field:'hf001',title:'洁面膏',colspan:2,align:'center'});
				columnsAll.push({field:'hf002',title:'紧肤水',colspan:2,align:'center'});
				columnsAll.push({field:'hf003',title:'润体乳',colspan:2,align:'center'});
				columnsAll.push({field:'hf004',title:'紧致<br/>乳霜',colspan:2,align:'center'});
				columnsAll.push({field:'hf005',title:'精华液',colspan:2,align:'center'});
				columnsAll.push({field:'hf011',title:'泰和<br/>三清',colspan:2,align:'center'});
				columnsAll.push({field:'ss001',title:'精油',colspan:2,align:'center'});
				columnsAll.push({field:'ss002',title:'紧肤膏',colspan:2,align:'center'});
				

				
				
				var columnsAll1 = new Array();
				
				
				columnsAll1.push({field:'lc002salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				/*columnsAll1.push({field:'rjdc',title:'单价',width:50,align:'center'});*/
				columnsAll1.push({field:'lc002salprice',title:'金额',width:50,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				
				columnsAll1.push({field:'lc001salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				/*columnsAll1.push({field:'jzzxse',title:'单价',width:50,align:'center'});*/
				columnsAll1.push({field:'lc001salprice',title:'金额',width:50,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				
				
				
				
				columnsAll1.push({field:'hf001salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf001salprice',title:'金额',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf002salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf002salprice',title:'金额',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf003salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf003salprice',title:'金额',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf004salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf004salprice',title:'金额',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf005salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf005salprice',title:'金额',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf011salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'hf011salprice',title:'金额',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'ss001salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'ss001salprice',title:'金额',width:50,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'ss002salnum',title:'数量',width:40,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll1.push({field:'ss002salprice',title:'金额',width:50,align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				var month = $("#dailyTotal_datebox").val();
				var organIds = $("#organIds").val();
				
				$('#dailySaleTotal_datagrid').datagrid({
					cls: "theme-datagrid",
					toolbar: '#sale_tb',
					singleSelect:true,
					fitColumns:false,
					rownumbers: true,
				    columns:[columnsAll,columnsAll1],
				    url: "${cxt!}/dailySaleTotalStatisticServices/getDailyTotal",
				    queryParams: {
						'month': month,
						'organIds':organIds
					},
				    onLoadSuccess:function(data){
				    	var n = data.total;
						 var rows = $('#dailySaleTotal_datagrid').datagrid('getRows');
						if(rows.length > 0){
							
							var pricetotal = compute_GXC('pricetotal');
							var dyxslj = compute_GXC('dyxslj');
							var cjrs = compute_GXC('cjrs');
							var zjscjrs = compute_GXC('zjscjrs');
							var zrjdcjrs = compute_GXC('zrjdcjrs');
							var lc002salnum = compute_GXC('lc002salnum');
							
							var lc002salprice = compute_GXC('lc002salprice');
							var lc001salnum = compute_GXC('lc001salnum');
							
							var lc001salprice = compute_GXC('lc001salprice');
							
							var zr = compute_GXC('zr');
							var zc = compute_GXC('zc');
							
							var hf001salnum = compute_GXC('hf001salnum');
							var hf001salprice = compute_GXC('hf001salprice');
							var hf002salnum = compute_GXC('hf002salnum');
							var hf002salprice = compute_GXC('hf002salprice');
							var hf003salnum = compute_GXC('hf003salnum');
							var hf003salprice = compute_GXC('hf003salprice');
							var hf004salnum = compute_GXC('hf004salnum');
							var hf004salprice = compute_GXC('hf004salprice');
							var hf005salnum = compute_GXC('hf005salnum');
							var hf005salprice = compute_GXC('hf005salprice');
							var hf011salnum = compute_GXC('hf011salnum');
							var hf011salprice = compute_GXC('hf011salprice');
							
							var ss001salnum = compute_GXC('ss001salnum');
							var ss001salprice = compute_GXC('ss001salprice');
							var ss002salnum = compute_GXC('ss002salnum');
							var ss002salprice = compute_GXC('ss002salprice');
							
							$('#dailySaleTotal_datagrid').datagrid('insertRow', {
								index: 0,
								row: {date: '合计',
									pricetotal:pricetotal,
									dyxslj:dyxslj,
									cjrs:cjrs,
									zjscjrs:zjscjrs,
									zrjdcjrs:zrjdcjrs,
									lc002salnum:lc002salnum,
									//rjdc:'',
									lc002salprice:lc002salprice,
									lc001salnum:lc001salnum,
									//jzzxse:'',
									lc001salprice:lc001salprice,
									
									zr:zr,
									zc:zc,
									
									hf001salnum:hf001salnum,
									hf001salprice:hf001salprice,
									hf002salnum:hf002salnum,
									hf002salprice:hf002salprice,
									hf003salnum:hf003salnum,
									hf003salprice:hf003salprice,
									hf004salnum:hf004salnum,
									hf004salprice:hf004salprice,
									hf005salnum:hf005salnum,
									hf005salprice:hf005salprice,
									hf011salnum:hf011salnum,
									hf011salprice:hf011salprice,
									
									ss001salnum:ss001salnum,
									ss001salprice:ss001salprice,
									ss002salnum:ss002salnum,
									ss002salprice:ss002salprice
									
								}
				             });
							
							$('#dailySaleTotal_datagrid').datagrid('insertRow', {
								index: 1,
								row: {date: '日均',
									pricetotal:(pricetotal/n).toFixed(1),
									dyxslj:(dyxslj/n).toFixed(1),
									cjrs:(cjrs/n).toFixed(1),
									zjscjrs:(zjscjrs/n).toFixed(1),
									zrjdcjrs:(zrjdcjrs/n).toFixed(1),
									lc002salnum:(lc002salnum/n).toFixed(1),
									//rjdc:(''/n).toFixed(1),
									lc002salprice:(lc002salprice/n).toFixed(1),
									lc001salnum:(lc001salnum/n).toFixed(1),
									//jzzxse:(''/n).toFixed(1),
									lc001salprice:(lc001salprice/n).toFixed(1),
									
									zr:(zr/n).toFixed(1),
									zc:(zc/n).toFixed(1),
									
									hf001salnum:(hf001salnum/n).toFixed(1),
									hf001salprice:(hf001salprice/n).toFixed(1),
									hf002salnum:(hf002salnum/n).toFixed(1),
									hf002salprice:(hf002salprice/n).toFixed(1),
									hf003salnum:(hf003salnum/n).toFixed(1),
									hf003salprice:(hf003salprice/n).toFixed(1),
									hf004salnum:(hf004salnum/n).toFixed(1),
									hf004salprice:(hf004salprice/n).toFixed(1),
									hf005salnum:(hf005salnum/n).toFixed(1),
									hf005salprice:(hf005salprice/n).toFixed(1),
									hf011salnum:(hf011salnum/n).toFixed(1),
									hf011salprice:(hf011salprice/n).toFixed(1),
									
									ss001salnum:(ss001salnum/n).toFixed(1),
									ss001salprice:(ss001salprice/n).toFixed(1),
									ss002salnum:(ss002salnum/n).toFixed(1),
									ss002salprice:(ss002salprice/n).toFixed(1)
									
								}
				             });
					
					
						} 
					}
				});
			}

			
			function  dateFormatter(){
				$('#dailyTotal_datebox').datebox({
				       //显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
				       onShowPanel: function () {
				          //触发click事件弹出月份层
				          span.trigger('click'); 
				          if (!tds)
				            //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
				            setTimeout(function() { 
				                tds = p.find('div.calendar-menu-month-inner td');
				                tds.click(function(e) {
				                   //禁止冒泡执行easyui给月份绑定的事件
				                   e.stopPropagation(); 
				                   //得到年份
				                   var year = /\d{4}/.exec(span.html())[0] ,
				                   //月份
				                   //之前是这样的month = parseInt($(this).attr('abbr'), 10) + 1; 
				                   month = parseInt($(this).attr('abbr'), 10);  

							         //隐藏日期对象                     
							         $('#dailyTotal_datebox').datebox('hidePanel').datebox('setValue', year + '-' + month); 
				                 });
				             }, 0);
				        },
				            //配置parser，返回选择的日期
				            parser: function (s) {
				                if (!s) return new Date();
				                var arr = s.split('-');
				                return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
				            },
				            //配置formatter，只返回年月 之前是这样的d.getFullYear() + '-' +(d.getMonth()); 
				            formatter: function (d) { 
				                var currentMonth = (d.getMonth()+1);
				                var currentMonthStr = currentMonth < 10 ? ('0' + currentMonth) : (currentMonth + '');
				                return d.getFullYear() + '-' + currentMonthStr; 
				            }
				        });

				        //日期选择对象
				        var p = $('#dailyTotal_datebox').datebox('panel'), 
				        //日期选择对象中月份
				        tds = false, 
				        //显示月份层的触发控件
				        span = p.find('span.calendar-text'); 
				        var curr_time = new Date();

				        //设置前当月
				        $("#dailyTotal_datebox").datebox("setValue", myformatter(curr_time));
			    
			 
			}

			//指定列求和
			function compute_GXC(colName) {
			     var rows = $('#dailySaleTotal_datagrid').datagrid('getRows');
			     var total = 0;
			     for (var i = 0; i < rows.length; i++) {
			    	 if(typeof(rows[i][colName]) != 'undefined'){
			    		 total += parseFloat(rows[i][colName]);
			    	 }
			     }
			     if(total > 0){
			    	 return total.toFixed(1);
			     }else{
			    	 return 0;
			     }
			}
			//格式化日期
			function myformatter(date) {
			    //获取年份
			    var y = date.getFullYear();
			    //获取月份
			    var m = date.getMonth() + 1;
			    return y + '-' + m;
			}
			//指定列求和
			function compute_GXC(colName) {
			     var rows = $('#dailySaleTotal_datagrid').datagrid('getRows');
			     var total = 0;
			     for (var i = 0; i < rows.length; i++) {
			    	 if(typeof(rows[i][colName]) != 'undefined'){
			    		 total += parseFloat(rows[i][colName]);
			    	 }
			     }
			     if(total > 0){
			    	 return total.toFixed(1);
			     }else{
			    	 return 0;
			     }
			}


		</script>
	</body>
</html>